﻿using SwenAssigment.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SwenAssigment
{
    public partial class BookingCheckOut : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Label6.Text = System.DateTime.Now.ToShortDateString() + " " + System.DateTime.Now.ToShortTimeString();
            string sss = (string)Session["bid"];
            if (Session["bid"] != null)
            {
                if (Label1.Text == "Label")
                {
                    string line = "select * from Room_Booking where Room_Booking_ID='" + sss + "'";
                    RADcon con = new RADcon();
                    string[] s = con.bretrieveone(line);
                    Label1.Text = s[0];
                    Label2.Text = s[1];
                    Label3.Text = s[2];
                    Label4.Text = s[3];
                    Label5.Text = s[4];
                    Label7.Text = s[9];
                    string[] s2 = con.raretrieveone("select * from room where Room_ID='" + s[9] + "'");
                    Label8.Text = s2[3];
                    DateTime d1 = DateTime.Parse(Label5.Text);
                    DateTime d2 = DateTime.Parse(Label6.Text);
                    TimeSpan span = d2 - d1;
                    int days = span.Days;
                    Label9.Text = days.ToString();
                    DateTime dt = DateTime.Parse(Label6.Text);
                    bool bl = false;
                    decimal acos = 0;
                    if (dt.Hour < 5 & dt.Hour > 0)
                    {
                        bl = true;
                        acos = decimal.Parse(Label8.Text) / 2;
                    }
                    Label10.Text = bl.ToString();
                    Label11.Text = acos.ToString();
                    decimal tcos = (decimal.Parse(Label8.Text) * (decimal.Parse(Label9.Text) + 1)) + decimal.Parse(Label11.Text);
                    Label12.Text = tcos.ToString();
                    if (Page.Request.UrlReferrer.LocalPath == "/BookingDetail.aspx")
                    {

                    }
                    else
                    {
                        Response.Redirect("RoomAvalibility.aspx");
                    }
                }
            }
            else
            {
                Response.Redirect("RoomAvalibility.aspx");
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            DateTime dt = DateTime.Parse(Label6.Text);
            RADcon con = new RADcon();
            bool bl = false;
            if (dt.Hour < 5 & dt.Hour > 0)
            {
                bl = true;
            }
            bool b = con.bupdateco(int.Parse(Label1.Text),Label6.Text,bl);
            if (b == true)
            {
                Pay p = new Pay();
                p.bookid=int.Parse(Label1.Text);
                p.addcost=decimal.Parse(Label11.Text);
                p.content = int.Parse(Label2.Text);
                p.paydetail=DropDownList2.Text;
                UserClass uc = (UserClass)Session["login"];
                p.handleby = uc.UserName;
                p.other=DropDownList1.Text;
                bool bp = con.pcreate(p);
                if (bp == true)
                {
                    int id = int.Parse(Label7.Text);
                    decimal cost = decimal.Parse(Label8.Text);
                    string stat = "Service";
                    bool bc = con.raupdate(id, cost, stat);
                    if (bc == true)
                    {
                        Session["mystat"] = "Check Out";
                        Response.Redirect("RoomAvalibility.aspx");
                    }
                }
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            decimal drink = DropDownList1.SelectedIndex * 50;
            DateTime dt = DateTime.Parse(Label6.Text);
            bool bl = false;
            decimal acos = 0;
            if (dt.Hour < 5 & dt.Hour > 0)
            {
                bl = true;
                acos = decimal.Parse(Label8.Text) / 2;
            }
            Label10.Text = bl.ToString();
            Label11.Text = (acos + drink).ToString();
            decimal tcos = (decimal.Parse(Label8.Text) * (decimal.Parse(Label9.Text) + 1)) + decimal.Parse(Label11.Text);
            Label12.Text = tcos.ToString();
        }
    }
}